﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YanZhiwei.DotNet2.Utilities.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.ObjectModel;
namespace YanZhiwei.DotNet2.Utilities.Common.Tests
{
    [TestClass()]
    public class TypeHelperTests
    {
        [TestMethod()]
        public void IsNullableTypeTest()
        {
            Assert.AreEqual(true, TypeHelper.IsNullableType(typeof(int?)));
            Assert.AreEqual(false, TypeHelper.IsNullableType(typeof(int)));
            Assert.AreEqual(true, TypeHelper.IsNullableType(typeof(Nullable<DateTime>)));
            Assert.AreEqual(false, TypeHelper.IsNullableType(typeof(DateTime)));
        }

        [TestMethod()]
        public void GetNonNullableTypeTest()
        {
            Assert.AreEqual(typeof(int), TypeHelper.GetNonNullableType(typeof(int?)));
            Assert.AreEqual(typeof(DateTime), TypeHelper.GetNonNullableType(typeof(Nullable<DateTime>)));
        }

        [TestMethod()]
        public void IsEnumerableTypeTest()
        {
            Assert.AreEqual(true, TypeHelper.IsEnumerableType(typeof(IEnumerable<string>)));
        }

        [TestMethod()]
        public void GetElementTypeTest()
        {
            Assert.AreEqual(typeof(DateTime), TypeHelper.GetElementType(typeof(Collection<DateTime>)));
        }

        [TestMethod()]
        public void IsKindOfGenericTest()
        {
            Assert.AreEqual(true, TypeHelper.IsKindOfGeneric(typeof(List<string>), typeof(IEnumerable<>)));

        }
    }
}
